/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.primecodegen.util;

//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.Date;

import java.util.Random;
import java.util.ResourceBundle;

/**
 * 
 * @author Administrator
 */
public class util {

    // this utilty will prevent the SQL injection and prevent facing error when
    // user enter quotes as input
    public static String RemoveExtraQuotes(String value) {
        return value.replace("'", "");
    }

    public static boolean isEmpty(String value) {
        return (((value == null) || value.equalsIgnoreCase(ComConstants.UNREALISTIC_STRING)) ? true
                : false);
    }

    public static boolean isEmpty(int value) {
        return ((value == ComConstants.UNREALISTIC_INT) ? true : false);
    }

    public static boolean isEmpty(byte value) {
        return ((value == ComConstants.UNREALISTIC_BIT) ? true : false);
    }

    public static boolean isEmpty(float value) {
        return ((value == ComConstants.UNREALISTIC_FLOAT) ? true : false);
    }

    public static boolean isEmpty(double value) {
        return ((value == ComConstants.UNREALISTIC_FLOAT) ? true : false);
    }

    public static boolean isEmpty(Date value) {
        return ((value == ComConstants.UNREALISTIC_DATE) ? true : false);
    }

    public static boolean isEmpty(boolean value) {
        return value;
    }

    public static boolean ConvertByteToBoolean(byte value) {
        return (value == new Byte("1") ? true : false);
    }

    public static String removeNullFrom(String string) {
        if (string == null) {
            return "";
        } else {
            return string;
        }
    }

    public static String generatePassword() {
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        char[] chars = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
            'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6',
            '7', '8', '9', '0', '$', '%', '#', '*'};

        for (int i = 0; i < 6; i++) {
            buffer.append(chars[random.nextInt(chars.length)]);
        }

        return buffer.toString();
    }

    public static void DeleteFile(String file) {
        String fileName = file;

        // A File object to represent the filename
        File f = new File(fileName);

        // Make sure the file or directory exists and isn't write protected
        if (!f.exists()) {
            throw new IllegalArgumentException(
                    "Delete: no such file or directory: " + fileName);
        }

        if (!f.canWrite()) {
            throw new IllegalArgumentException("Delete: write protected: "
                    + fileName);
        }

        // If it is a directory, make sure it is empty
        if (f.isDirectory()) {
            String[] files = f.list();

            if (files.length > 0) {
                throw new IllegalArgumentException(
                        "Delete: directory not empty: " + fileName);
            }
        }

        // Attempt to delete it
        boolean success = f.delete();

        if (!success) {
            throw new IllegalArgumentException("Delete: deletion failed");
        }
    }

    public static String toCamelCase(String s) {
        String[] parts = s.split("_");
        String camelCaseString = "";
        for (String part : parts) {
            camelCaseString = camelCaseString + toProperCase(part);
        }

        return camelCaseString;
    }
    public static String toCamelCaseFirstLower(String s) {
        String[] parts = s.split("_");
        String camelCaseString = "";
        for (String part : parts) {
            camelCaseString = camelCaseString + toProperCase(part);
        }
    
        
        return firstToLowerCase(camelCaseString);
    }

    public static String toBeanPattern(String s) {
        String[] parts = s.split("_");
        String camelCaseString = "";
        for (String part : parts) {
            camelCaseString = camelCaseString + toProperCase(part);
        }
        return camelCaseString;
    }

    public static String toProperCase(String s) {
        return s.substring(0, 1).toUpperCase()
                + s.substring(1).toLowerCase();
    }

    public static String firstToLowerCase(String s) {
        String s1 = s.charAt(0) + "";
        s1=s1.toLowerCase();
        char[] z = s.toCharArray();
        z[0]=s1.charAt(0);
        String newString = new String(z);
            
      
        return newString;
    }

    public static String getBundleValue(String key) {
        String value = "";
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("com.primecodegen.resources.SystemManager");
            value = bundle.getString(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;

    }
    
    
    public static void createDirectory(String Path) {
        try {
            String strDirectoy = Path;
            //String strManyDirectories = "dir1/dir2/dir3";

            // Create one directory
            boolean success = (new File(strDirectoy)).mkdir();
            if (success) {
                System.out.println("Directory: " + strDirectoy + " created");
            }

            // Create multiple directories
//			boolean success = (new File(strManyDirectories)).mkdirs();
//			if (success) {
//				System.out.println("Directories: " + strManyDirectories
//						+ " created");
//			}

        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }

    public static void createFile(String Path) throws IOException {
        File f;
        f = new File(Path);
        if (!f.exists()) {
            f.createNewFile();
            System.out.println("New has been created to the current directory");

        }

    }

    public static void createDirectories(String path) {
        try {
            //"dir1/dir2/dir3"
            String strManyDirectories = path;



            // Create multiple directories
            boolean success = (new File(strManyDirectories)).mkdirs();
            if (success) {
                System.out.println("Directories: " + strManyDirectories + " created");
            }

        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
    
        public static void main(String[] args) {
//        util.createDirectories("src\\java\\cc\\mm\\nn\\pp");
//            System.out.println(firstToLowerCase("MohaMmad"));
            System.out.println(toCamelCaseFirstLower("user_role_services"));
            System.out.println(toCamelCase("user_role_services"));

    }
}
